package com.niit.activity.service;

import com.niit.activity.entity.Comment;
import com.niit.activity.mapper.CommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentService {
    @Autowired
    private CommentMapper commentMapper;
    
    public void addComment(Comment comment) {
        try {
            commentMapper.insertComment(comment);
            commentMapper.incrementActivityCommentCount(comment.getActivityId());
        } catch (Exception e) {
            // 记录异常
            e.printStackTrace();
            throw new RuntimeException("Failed to add comment", e);
        }
    }


    public List<Comment> getCommentsByActivityId(Long activityId) {
        return commentMapper.selectCommentsByActivityId(activityId);
    }

    public List<Comment> getCommentsByParentId(Long parentId) {
        return commentMapper.selectCommentsByParentId(parentId);
    }
}